using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using CMS.Core.DataInterfaces;
using CMS.Core.Domain;
using CMS.Data;
using AjaxPro;

namespace CMS.Presenters
{
    public class ListNSDPresenter
    {
        IList parentList;
        IListNSDView view;
        INguoiSuDungDao dataService;


        //Attaches this presenter to the view's events.
        public ListNSDPresenter(IListNSDView view, INguoiSuDungDao dataService)
        {
            this.view = view;
            this.dataService = dataService;
            SubscribeViewToEvents();
        }

        public ListNSDPresenter()
        {
           this.dataService = NHibernateDaoFactory.Instance.GetNguoiSuDungDao();
        }

        void SubscribeViewToEvents()
        {
            view.Load += OnViewLoad;
        }

        void OnViewLoad(object sender, EventArgs e)
        {
            if (!view.IsPostBack)
            {
               // LoadViewFromModel();
            }
        }

        public void LoadViewFromModel(string maNSD)
        {
            this.parentList = this.dataService.GetListPhongBan();

            view.ParentList = this.parentList;
            //view.IsRole = NHibernateDaoFactory.Instance.GetKiemTraQuyenDao().CheckQuyenCapNhatThongTinDanhMuc(maNSD);
        }

        [AjaxMethod]
        public IList GetListNguoiSuDung()
        {
            return this.dataService.GetListPhongBan();
        }

        [AjaxMethod]
        public IList<NguoiSuDungEx> GetNguoiSuDungOfPhongBan(string divName, int Min, int Max, bool isPage)
        {
            return this.dataService.ConvertToNguoiSuDungEx(this.dataService.GetNguoiSuDungOfPhongBan(divName, Min, Max, isPage));
        }

        [AjaxMethod]
        public bool DeleteByIDs(string code)
        {
            return dataService.UpdateStatusListIDs(code);
            
        }

       
    }
}
